#xxxxxxxxxxxxxxxxxxxxxxxxxxx 收集并拷贝运行时依赖
#安装主程序
install(TARGETS demo RUNTIME DESTINATION bin)

# 收集依赖
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
    EXECUTABLES "$<TARGET_FILE:demo>"
    RESOLVED_DEPENDENCIES_VAR deps
    UNRESOLVED_DEPENDENCIES_VAR unresolved
    # DIRECTORIES
        # "$ENV{HOME}/.conan2/p"
        # "$<TARGET_FILE_DIR:demo>" # 动态库 的附加搜索目录
        # "${PROJECT_BINARY_DIR}/lib"  # 添加项目库目录
        #"${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-linux/lib"  # 添加项目库目录
    # PRE_EXCLUDE_REGEXES  # 排除系统库正则
        # "ld-[A-Za-z0-9_-.]+.so"
    # POST_EXCLUDE_REGEXES  # 二次过滤
        # "*/lib64/"
    POST_INCLUDE_REGEXES
        "libfmt.*"
        "libspdlog.*"
)

# 打印解析出的依赖库 (调试用)
message(STATUS "Resolved dependencies:")
foreach(lib IN LISTS deps)
    message(STATUS "  - ${lib}")
endforeach()

# 处理获取结果
if(unresolved_deps)
    message(WARNING "Unresolved dependencies: ${unresolved_deps}")
endif()

# 复制所有解析出的依赖库到安装目录
foreach(lib ${deps})
    file(INSTALL "${lib}"
        DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
        FOLLOW_SYMLINK_CHAIN
        )
endforeach()

]])


include(InstallRequiredSystemLibraries)
install(TARGETS ${MYEXE} DESTINATION bin)
set(CPACK_GENERATOR "ZIP")       # Windows 用 ZIP/NSIS, macOS 用 DragNDrop
set(CPACK_PACKAGE_NAME "Demo")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_SOURCE_DIR}/dist_package")
include(CPack)